<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>销售单位管理</title>
    <#include "${ctx.getContextPath()}/css.jsp" parse=true encoding="utf-8">
</head>
<body>
<#include "${ctx.getContextPath()}/js.jsp" parse=true encoding="utf-8">
<div class="page">
    <header class="bar bar-nav">
        <a class="button button-link button-nav pull-left external " href="/home/index" data-transition='slide-out'>
            <span class="icon icon-left"></span>
            返回
        </a>
        <h1 class="title">销售单位管理</h1>
    </header>
    <div class="content">
        <div class="card">
            <div class="card-content">
                <div class="card-content-inner">
                    <div class="content-padded">
                        <div class="searchbar row">
                            <div class="search-input col-70">
                                <label class="icon icon-search" for="companyName"></label>
                                <input type="search" name="companyName" id='companyName' placeholder='销售商名称'/>
                            </div>
                            <a href="#" onclick="getfirstList();"
                               class="button button-fill button-primary  external  col-15">查询</a>
                            <a href="${ctx.getContextPath()}/company/gotoAdd"
                               class="button button-fill button-primary  external  col-15">新增</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-content">
                <div class="card-content-inner">
                    <div class=" infinite-scroll row" data-distance="100">
                        <div class="list-block media-list">
                            <ul class="list-container">
                            </ul>
                        </div>
                        <div class="infinite-scroll-preloader">
                            <div class="preloader"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var loading = false;
    var itemsPerLoad = 20;
    var number = 1;
    getfirstList();
    var lastIndex = 20;
    $(document).on('infinite', '.infinite-scroll', function () {
        // 如果正在加载，则退出
        if (loading) return;
        // 设置flag
        loading = true;
        getCompanyList();
        lastIndex = $('.list-container li').length;
        loading = false;
    });

    //第一次进行查询数据，获取list
    function getfirstList() {
        $('.list-container').children().filter('li').remove();
        getCompanyList();
    }

    //获取公司列表
    function getCompanyList() {
        $.ajax({
            type: "POST",//方法类型
            dataType: "json",
            url: "/company/ajaxCompany",
            data: {
                companyName: $("#companyName").val(),
                pageSize: itemsPerLoad,
                currentPage: number,
            },
            success: function (result) {
                if (result.code == 200) {
                    var dataLi = result.data;
                    var html = '';
                    $.each(dataLi, function (index, items) {
                        var phonyNumber = "";
                        if (items.phonyNumber != null) {
                            phonyNumber = items.phonyNumber;
                        }
                        var companyAddress = "";
                        if (items.companyAddress != null) {
                            companyAddress = items.companyAddress;
                        }
                        html += '<li><a href="${ctx.getContextPath()}/company/companyInfo?companyId=' + items.uuid + '" class="item-link item-content external">' +
                            ' <div class="item-inner">' +
                            ' <div class="item-title-row">' +
                            '<div class="item-title">' + items.companyName + '</div>' +
                            '<div class="item-after">' + phonyNumber + '</div>' +
                            ' </div>' +
                            ' <div class="item-subtitle">' + items.corporation + '</div>' +
                            ' <div class="item-text">' + companyAddress + '.</div>' +
                            ' </div>' +
                            '</a> </li>';
                    });
                    $('.list-container').append(html);
                } else {
                }
            },
            error: function () {
                alert("系统异常！");
            }
        });
    }
</script>
<style type="text/css">
    .infinite-scroll-preloader {
        margin-top: -20px;
    }
</style>
</body>
</html>